/*
 * $Id: ClientFilter.java 23 2002-09-29 13:59:30Z bpruessmann $
 *
 * Copyright (c) 2001 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.p4eclipse.internal.ui.views.submitted;

import net.sourceforge.p4eclipse.core.api.IChangesResult;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

/**
  * @version 	$Revision: 23 $
  * @author		<a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class ClientFilter extends ViewerFilter
{
	private String clientName;
	private boolean negate;
	
	/** Creates a new ClientFilter instance. */
	public ClientFilter() { }

	/** @see ViewerFilter#select(Viewer, Object, Object) */
	public boolean select(Viewer viewer, Object parentElement, Object element)
	{
		if (!(element instanceof IChangesResult))
			return false;
			
		if (clientName == null)
			return true;
			
		return negate ? !internalSelect(element) : internalSelect(element);
	}

	private boolean internalSelect(Object element)
	 {
		IChangesResult changesResult = (IChangesResult)element;	
		return clientName.equals(changesResult.getClientName());
	}
	
	/** Sets the clientName. 
	  * @param clientName The clientname to set
	  */
	public void setClientName(String clientName)
	{
		this.clientName = clientName;
	}

	/** Sets the internal negation flag. */
	public void setNegate(boolean negate)
	{
		this.negate = negate;
	}
}
